package gaileenchess.tests;
import gaileenchess.*;

public class KingTest extends Test
{
    public KingTest()
    {
        super("King");
    }
    
    protected boolean doTests()
    {
        return test1();
    }
    
    private static Piece[][] boardConfig1()
    {
        Piece[][] pos = new Piece[8][8];
        
        /*
        
            a    b    c    d    e    f    g    h  
           ---- ---- ---- ---- ---- ---- ---- ----
        8 |    | BN |    |    |    |    | BN |    | 7
           ---- ---- ---- ---- ---- ---- ---- ----
        7 |    |    | BP | BP |    | BP |    |    | 6
           ---- ---- ---- ---- ---- ---- ---- ----
        6 |    |    |    |    | BP |    |    |    | 5
           ---- ---- ---- ---- ---- ---- ---- ----
        5 |    |    |    | WK | BQ |    |    |    | 4
           ---- ---- ---- ---- ---- ---- ---- ----
        4 |    |    |    | WP |    |    |    |    | 3
           ---- ---- ---- ---- ---- ---- ---- ----
        3 |    | WP |    |    |    |    |    |    | 2
           ---- ---- ---- ---- ---- ---- ---- ----
        2 | WP |    |    |    |    |    | WP |    | 1
           ---- ---- ---- ---- ---- ---- ---- ----
        1 |    | WN |    |    |    |    |    |    | 0
           ---- ---- ---- ---- ---- ---- ---- ----
            0    1    2    3    4    5    6    7
        
        
        */
        
        Board.addPiece(pos, new Knight(Common.Side.WHITE, 0, 1));
        Board.addPiece(pos, new Pawn(Common.Side.WHITE, 1, 0));
        Board.addPiece(pos, new Pawn(Common.Side.WHITE, 1, 6));
        Board.addPiece(pos, new Pawn(Common.Side.WHITE, 2, 1));
        Board.addPiece(pos, new Pawn(Common.Side.WHITE, 3, 3));
        
        Board.addPiece(pos, new King(Common.Side.WHITE, 4, 3));
        
        
        Board.addPiece(pos, new Queen(Common.Side.BLACK, 4, 4));
        Board.addPiece(pos, new Pawn(Common.Side.BLACK, 5, 4));
        Board.addPiece(pos, new Pawn(Common.Side.BLACK, 6, 2));
        Board.addPiece(pos, new Pawn(Common.Side.BLACK, 6, 3));
        Board.addPiece(pos, new Pawn(Common.Side.BLACK, 6, 5));
        Board.addPiece(pos, new Knight(Common.Side.BLACK, 7, 1));
        Board.addPiece(pos, new Knight(Common.Side.BLACK, 7, 6));
        
        return pos;
    }
    
    private boolean test1()
    {
        boolean pass = true;
        
        Piece[][] boardConfig = boardConfig1();
        Board board = new Board(boardConfig);
        
        Piece whiteKing = boardConfig[4][3];
        Board.Position pos = new Board.Position(4, 3);
        
        pass &= (whiteKing.getType() == Piece.Type.KING);
        pass &= (whiteKing.getSide() == Common.Side.WHITE);
        pass &= (whiteKing.getRow() == 4 && whiteKing.getCol() == 3);
        
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(5,4));
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(4,4));
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(3,4));
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(3,2));
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(4,2));
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(5,2));
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(5,3));
        
        pass &= whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(3,3));
        pass &= !(board.isValidMove(0, pos, new Board.Position(3,3)));
        
        
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(2,3)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(2,2)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(7,6)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(0,7)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(0,0)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(6,5)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(7,6)));
        pass &= !(whiteKing.isValidMove(Common.Side.WHITE, board, pos, new Board.Position(7,0)));
        
        printSuccess(pass, "test1");
        
        return pass;
    }
}
